package org.yhx.learning;/*
 * Copyright (C), 2024, bigmoon
 * FileName:
 * Author:   bigmoon
 * Date:     2024/7/19 17:50
 * Description: //模块目的、功能描述
 * History: //修改记录
 * &lt;author&gt;      &lt;time&gt;      &lt;version&gt;    &lt;desc&gt;
 * 修改人姓名             修改时间            版本号                  描述
 */

import io.netty.channel.EventLoop;
import io.vertx.core.Future;
import io.vertx.core.Vertx;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.file.FileSystem;
import io.vertx.core.file.OpenOptions;

public class FileOperation {

    public static void main(String[] args) {

        Vertx vertx=Vertx.vertx();
        FileSystem fileSystem = vertx.fileSystem();

        //future
//        Future<Void> file = fileSystem.createFile("target\\\\future.txt");
//        file.compose(Void -> {
//            System.out.println("文件创建成功");
//            return null;
//        }).compose(result->{
//            System.out.println("write file");
//            return null;
//        });

        System.out.println("-----------------red--------------------");
        OpenOptions openOptions = new OpenOptions().setRead(true);
        fileSystem.open("target\\\\future.txt",openOptions,asyncResult->{

            if(asyncResult.succeeded()){

                 asyncResult.result().handler(buffer->{
                     System.out.println(buffer);
                 }).exceptionHandler(result->{
                     System.out.println(result.getMessage());
                 }).endHandler((Void)-> System.out.println(Thread.currentThread().getName()+":读完了"));
            }else{
                System.out.println("获取文件失败");
            }


        });

        //2. handler as a parameter
//        fileSystem.createFile("target\\vertFile.txt",it->{
//
//            if (it.succeeded()) {
//                System.out.println("文件创建成功");
//            }else
//                System.out.println("文件创建失败");
//        });
        System.out.println("over");

    }



}
